const path = require('path');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

function resolve(dir) {
    return path.join(__dirname, dir);
}
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
    publicPath: process.env.NODE_ENV === 'development' ? '/' : '/',
    chainWebpack: config => {
        config.module
            .rule('images')
            .use('url-loader')
            .loader('url-loader')
            .tap(options => Object.assign(options, {
                limit: 2048
            }));
        config.resolve.alias
            .set('@', resolve('src'))
            .set('assets', resolve('src/assets'))
            .set('views', resolve('src/views'))
            .set('components', resolve('src/comon/components'))
            .set('http', resolve('src/http'));
    },
    css: {
        loaderOptions: {
            sass: {
                data: `@import "@/assets/css/style.scss";`
            }
        }
    },
    devServer: {
        proxy: {
            '/api': {
                target: 'http://192.168.1.235/',
                // target: 'http://192.168.89:8040/',
                pathRewrite: {
                    '^/api': ''
                },
                changeOrigin: true,
                secure: false, // 接受 运行在 https 上的服务
            }
        }, // 跨域代理
    },
    configureWebpack: {
        externals: {
            'vue': 'Vue',
            'vuex': 'Vuex',
            'vue-router': 'VueRouter',
            'element-ui': 'ELEMENT'
        },
        plugins: [
            // new BundleAnalyzerPlugin()
        ]
    },
    transpileDependencies: [
        'vue-echarts', 'resize-detector',
        /\/node_modules\/vue-echarts\//,
        /\/node_modules\/resize-detector\//
    ]
};